<!--#include file="./header.inc"-->
<%

select case aq
	'class
	case "edit" 		: 	call edit
	case "save" 		: 	call save
	case "delete" 		: 	call delete
	case "status" 		: 	call status
	case "editbatch" 	: 	call editBatch
	case "savebatch" 	: 	call saveBatch
	case else 			: 	call index
end select

call db.close()

function index()
	genreID = admin.joinID(request("genreID"))
	sql = "select classID,className,genreID,classViewID,contentViewID,isStop from cj_class"
	if genreID <> "0" then sql = sql & " where genreID in(" & genreID & ")"
	sql = sql & " Order By genreID desc,classID desc"
	temp = db.arrayData(sql, page, rows)
	infoTotal = temp(0)
	data = temp(1)
	%><!--#include file="./view/class.index.html"--><%
end function

function edit()
	data = array("0","","0","0","0")
	if iid > 0 then
		set rs = db.exec("select genreID,className,classViewID,contentViewID,isStop from cj_class where classID=" & iid, 1)
		if not(rs.eof) then
			data = rs
		end if
		set rs = nothing
	end if
	%><!--#include file="./view/class.edit.html"--><%
end function

function save()
	className = admin.filter(request.form("className"))
	if className = "" then admin.message "栏目名称不能为空！"
	if iid = 0 then
		genreID = app.int(request.form("genreID"))
		if not isArray(app.getGenreInfo(genreID)) then admin.message "栏目所属大类不存在！"
	end if
	sql = "select * from cj_class"
	if iid > 0 then
		sql = sql & " where classID=" & iid
	end if
	set rs = db.exec(sql, 3)
	if iid = 0 then
		rs.AddNew
		rs("genreID") = genreID
	else
		if rs.eof then admin.message "栏目ID不存在！"
	end if
	rs("className") = className
	rs("classViewID") = app.int(request.form("classViewID"))
	rs("contentViewID") = app.int(request.form("contentViewID"))
	rs.update
	rs.close : set rs = nothing
	admin.updateWebAllData()
	if iid > 0 then
		admin.back "修改成功！", "返回列表", "?q=index"
	else
		admin.back "添加成功！", "继续添加", "?q=edit"
	end if
end function

function delete()
	sql = "select count(classID),"
	sql = sql & "(select count(classID) from cj_news where classID in(" & batchId & ")),"
	sql = sql & "(select count(classID) from cj_book where classID in(" & batchId & "))"
	sql = sql & " from cj_product where classID in(" & batchId & ")"
	set rs = db.exec(sql, 1)
	if rs(0) > 0 or rs(1) > 0 or rs(2) > 0 then
		app.json "正在使用的栏目不可以删除！",1
	end if
	call db.exec("Delete from cj_class where classID in(" & batchId & ")", 1)
	admin.updateWebAllData()
	app.json "删除成功！", 0
end function

function status()
	dim isStop, msg
    isStop = app.cj_bool(request("isStop"))
    msg = "启用"
    if isStop then
        msg = "禁用"
    end if
	call db.exec("update cj_class set isStop=" & isStop & " where classID in(" & batchId & ")", 1)
	admin.updateWebAllData()
	app.json msg & "成功！", 0
end function

function editBatch()
	%><!--#include file="./view/class.editBatch.html"--><%
end function

function saveBatch()
	dim classViewID, isClassViewID, contentViewID, isContentViewID, isIsStop, isStop, data()
	isClassViewID = admin.isCheck(request.form("isClassViewID"))
	isContentViewID = admin.isCheck(request.form("isContentViewID"))
	isIsStop = admin.isCheck(request.form("isIsStop"))
	if not(isClassViewID) and not(isContentViewID) and not(isIsStop) then admin.message "需要选择一项！"
	classViewID = app.int(request.form("classViewID"))
	contentViewID = app.int(request.form("contentViewID"))
	isStop = admin.isCheck(request.form("isStop"))
	set rs = db.exec("select * from cj_class where classID in(" & batchId & ")", 3)
	do until rs.eof
		if isClassViewID then
			rs("classViewID") = classViewID
		end if
		if isContentViewID then
			rs("contentViewID") = contentViewID
		end if
		if isIsStop then
			rs("isStop") = isStop
		end if
		rs.update
		rs.movenext
	loop
	rs.close : set rs = nothing
	admin.updateWebAllData()
	admin.back "批量修改成功！", "返回", "?q=index"
end function

%>